home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / clipper / ks94an.zip / ISAVERAG.HDR < prev    next >
Text File  |  1994-04-25  |  3KB  |  86 lines

  1. /******************************************************************************
  2.                  The Klipper Library, for CA-Clipper 5.x
  3.         Copyright (c), 1994, Wallace Information Systems Engineering
  4.  
  5. FUNCTION:
  6.  
  7. _IsAverage( anArray, nRange ) --> nElement
  8.  
  9. PARAMETERS:
  10.  
  11. anArray : Array to average and return element from
  12. nRange  : 0  = return nearest without EXceeding average
  13.           1  = Return nearest (DEFAULT)
  14.           2  = Return nearest without PREceeding average
  15.  
  16. SHORT:
  17.  
  18. Determine the array element that contains the average value of the array.
  19.  
  20. DESCRIPTION:
  21.  
  22. _IsAverage() returns the element number of an array that is or is closest to
  23. the average of the values in the array according to the option specified in
  24. nRange.
  25.  
  26. If nRange = 0, the element that contains the HIGHEST value BELOW the array
  27. average is returned.  That is, the closest value for n < AVERAGE (ie, "who
  28. of the below average group is closest to average?")
  29.  
  30. If nRange = 1, the element that is closest to the array average is returned,
  31. regardless of whether it is higher, lower or equal to the array average. (ie,
  32. "who of the entire group is closest to the group's average?")
  33.  
  34. If nRange = 2, the element that contains the LOWEST value ABOVE the array
  35. average is returned.  That is, the closest value for n > AVERAGE (ie, "who
  36. of the above average group are closest to average?).
  37.  
  38. NOTE:
  39.  
  40. The lowside and highside ranges return the element number that contains the
  41. closest to the average without equaling it.
  42.  
  43. Thus:
  44.  
  45. #define LOW     0
  46. #define CLOSEST 1
  47. #define HIGH    2
  48.  
  49. ar := { 1,2,3,4,5,6,7,8,9 }
  50.  
  51. The average is 5
  52.  
  53. The LOW range closest is 4
  54. The HIGH range closest is 6
  55.  
  56. The CLOSEST range closest is 5 itself, because CLOSEST includes EQUALITY
  57. whereas LOW and HIGH EXCLUDE equality.
  58.  
  59. EXAMPLE:
  60.  
  61. #define LOW     0
  62. #define CLOSEST 1
  63. #define HIGH    2
  64.  
  65. LOCAL anNums1 := { 12.1, 2.2, 7.3, 2.6, 5.9, 6.06, 0.5 } // 5.24
  66.  
  67. i = _IsAverage(anNums1) // defaults to CLOSEST
  68.  
  69. Result: The average of the values in anArray is 5.24, so the closest value is
  70. 5.9.  Therefore, i == 5 because anArray[5] == 5.9.
  71.  
  72. i = _IsAverage(anNums1,LOW)
  73.  
  74. Result:  The average of the values in anArray is 5.24, so the closest value
  75. without exceeding the average is 2.6.  Therefore, i == 4 because anArray[4]
  76. == 2.6
  77.  
  78.  
  79. i = _IsAverage(anNums1,HIGH)
  80.  
  81. Result:  The average of the values in anArray is 5.24, so the closest
  82. value without PRECEEDING the average is 5.9.  Therefore, i == 4 because
  83. anArray[5] == 5.9
  84.  
  85. ******************************************************************************/
  86.